package com.bob.debt.callback.factory;

import com.bob.debt.callback.CallbackHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
public class CallbackContext {

    private Map<String, BeanPropertiesWrapper> decoratorMaps;

    public CallbackContext(Map<String, BeanPropertiesWrapper> decoratorMaps) {
        log.debug("Init decoratorMaps:{}", decoratorMaps);
        this.decoratorMaps = decoratorMaps;
    }

    public <T extends CallbackHandler> T getInstance(String typeCode, Class<T> clz) {
        BeanPropertiesWrapper beanPropertiesWrapper = decoratorMaps.get(typeCode);
        return (T) BeanUtils.getBeanByProperties(beanPropertiesWrapper);
    }
}
